<template>
	<view class="wrap">
		<view class="search">
			<u-search v-model="keywords" @custom="search" @search="search"></u-search>
		</view>
		<scroll-view class="scroll-list msg-list-item" scroll-y="true" @scrolltolower="loadMore">
			<u-card :title="item.title" v-for="(item, index) in list" :key="index" :sub-title="selectDictLabel(categoryList,item.category)" padding="20" margin="0rpx 20rpx" thumb="/static/aidex/images/list-icon.png" @click="navTo('/pages/sys/msg/notice-detail?id='+item.id)">
				<view class="" slot="body">
					<view class="u-body-item u-flex  u-col-between u-p-t-0">
						<view class="u-body-item-title u-line-2"><rich-text :nodes="item.content"></rich-text></view>
					</view>
				</view>
				<view class="" slot="foot" style="text-align: right;font-size:5pt">{{item.createTime}}</view>
			</u-card>
			<u-loadmore :status="loadStatus" bgColor="#f2f2f2"></u-loadmore>
		</scroll-view>
	</view>
</template>
<script>
/**
 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
 */
export default {
	data() {
		return {
			keywords: '',
			query: {
				current: 1,
				size: 20
			},
			list: [],
			pages: 0,
			loadStatus: 'loadmore',
			categoryList:[]
		};
	},
	onLoad() {
		this.initCategory();
		this.loadList();
	},
	methods: {
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		initCategory() {
			this.$u.api.dictData({
				code: 'notice'
			}).then(res => {
				this.categoryList = res.data;
			});
		},
		search(value) {
			this.list = [];
			this.query.current = 0;
			this.query.title = value;
			this.loadList();
		},
		loadList() {
			this.$u.api.notice.list(this.query).then(res => {
				if (!res.data.records || res.data.records.length == 0) {
					this.loadStatus = "nomore";
					return;
				}
				this.list = this.list.concat(res.data.records);
				this.pages = res.pages;
				this.query.current = res.data.current;
				this.query.size = res.data.size;
				this.loadStatus = "loadmore";
			});
		},
		loadMore() {
			this.loadStatus = "loading";
			setTimeout(() => {
				this.query.current += 1;
				this.loadList();
			}, 100);
		},
		
	}
};

</script>
<style lang="scss">
@import '../../../common/uni.css';
page {
	background-color: #f5f5f5;
}
.wrap .search{
	background: #ffffff;
}
.msg-time{
	font-size: 26rpx;
	padding: 10px 0;
	color: #999999;
	text-align: center;
}
.u-card__foot{
	.u-icon{
		margin-right: 10px;
	}
}


</style>
